<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>demo书写项目里验证的东西</title>
  </head>
  <body></body>
  <script>
    let str = '我爱我冉'
    str = str.replace(/我/g, '<span style="color:red">我</span>')
    document.body.innerHTML = str
    let str1 = 'abcdbc'
    str1 = str1.replace(
      /a|c/gi,
      (item) => `<span style="color:red">${item.toUpperCase()}</span>`
    )
    document.body.innerHTML = str1
    // 封装高亮函数
    function heighLight(str, keyword) {
      const reg = new RegExp(keyword, 'gi')
      return str.replace(reg, (item) => {
        return `<span style="color:red">${item}</span>`
      })
    }
  </script>
</html>
